
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.default = void 0;

const _extends2 = _interopRequireDefault(require('@babel/runtime/helpers/extends'));

const _utils = require('../utils');

const _relation = require('../mixins/relation');

const _createNamespace = (0, _utils.createNamespace)('swipe-item');
const createComponent = _createNamespace[0];
const bem = _createNamespace[1];

const _default = createComponent({
  mixins: [(0, _relation.ChildrenMixin)('vanSwipe')],
  data: function data() {
    return {
      offset: 0,
      mounted: false,
    };
  },
  mounted: function mounted() {
    const _this = this;

    this.$nextTick(() => {
      _this.mounted = true;
    });
  },
  computed: {
    style: function style() {
      const style = {};
      const _this$parent = this.parent;
      const { size } = _this$parent;
      const { vertical } = _this$parent;
      style[vertical ? 'height' : 'width'] = `${size}px`;

      if (this.offset) {
        style.transform = `translate${vertical ? 'Y' : 'X'}(${this.offset}px)`;
      }

      return style;
    },
    shouldRender: function shouldRender() {
      const { index } = this;
      const { parent } = this;
      const { mounted } = this;

      if (!parent.lazyRender) {
        return true;
      } // wait for all item to mount, so we can get the exact count


      if (!mounted) {
        return false;
      }

      const active = parent.activeIndicator;
      const maxActive = parent.count - 1;
      const prevActive = active === 0 ? maxActive : active - 1;
      const nextActive = active === maxActive ? 0 : active + 1;
      return index === active || index === prevActive || index === nextActive;
    },
  },
  render: function render() {
    const h = arguments[0];
    return h('div', {
      class: bem(),
      style: this.style,
      on: (0, _extends2.default)({}, this.$listeners),
    }, [this.shouldRender && this.slots()]);
  },
});

exports.default = _default;
